import F2 from '../../f2-canvas/lib/f2';
var config = require("../config.js")
var PollingSocket = require("../../utils/socket.js")
// var disabledToken = require("../disabledToken.js")

// use gaode map service
var gaodeConfig = require("../../utils/gaodeConfig.js")
var amapFile = require('../../utils/amap-wx.js');
var broadcast = require("../../utils/broadcast.js")
let chart = null;
const app = getApp()
function initChart(canvas, width, height) { // 使用 F2 绘制图表
  const data = [
    { year: '周一', sales: 38 },
    { year: '周二', sales: 52 },
    { year: '周三', sales: 61 },
    { year: '周四', sales: 145 },
    { year: '周五', sales: 48 },
    { year: '周六', sales: 38 },
    { year: '周日', sales: 38 }
  ];
  chart = new F2.Chart({
    el: canvas,
    width,
    height
  });

  chart.source(data, {
    sales: {
      tickCount: 5
    }
  });
  chart.tooltip({
    showItemMarker: false,
    onShow(ev) {
      const { items } = ev;
      items[0].name = null;
      items[0].name = items[0].title;
      items[0].value = '¥ ' + items[0].value;
    }
  });
  chart.interval().position('year*sales');
  chart.render();
  return chart;
}
Page({
  data: {
    backgroundColor: 'rgb(89, 180, 49)',
    weekColor:'#fff',
    backgroundColor1: '#ccc',
    monthColor: 'black',
    f2_hidden:true,
    opts: {
      onInit: initChart
    }
  },
  onLoad: function (options) {
    //查看是否授权
        
  } ,
  week: function () {
    var that = this
    that.setData({
      backgroundColor: 'rgb(89, 180, 49)',
      weekColor: '#fff',
      backgroundColor1: '#ccc',
      monthColor: 'black',
      f2_hidden:true
    })
  },
  month:function(){
    var that=this
    that.setData({
      backgroundColor1: 'rgb(89, 180, 49)',
      monthColor: '#fff',
      backgroundColor: '#ccc',
      weekColor: 'black',
      f2_hidden:false
    })
  },
  onShow:function(options){
    wx.getSetting({
      success: (response) => {
        console.log(response)
        if (response.authSetting['scope.userInfo'] == true) {
          wx.authorize({
            scope: 'scope.userInfo',
            success: () => {
              console.log('已授权获取用户信息')
            }, fail: () => {
              console.log("未授权获取用户信息")
            }
          })
        } else {
          wx.redirectTo({
            url: '../confirm/confirm',
          })
        }
      }
    })
  },
  myAccount:function(){
    wx.navigateTo({
      url: '../myAccount/myAccount',
    })
  },
  myOrder:function(){
    wx.navigateTo({
      url: '../myOrder/myOrder',
    })
  },
  myEquipment:function(){
    wx.navigateTo({
      url: '../myEquipment/myEquipment',
    })
  }
});